package main

import (
	"github.com/gin-gonic/gin"
	"go-sdk/kam_op"
	"net/http"
	"strings"
)

type ReqBody struct {
	FromName string `json:"from_name"`
	FromWxid string `json:"from_wxid"`
	Content string `json:"content"`
	ToWxid string `json:"to_wxid"`
	ToName string `json:"to_name"`
	Msg string `json:"msg"`
	OriginalContent string `json:"original_content"`
	MsgId string `json:"msg_id"`
	MsgType string `json:"msg_type"`
	FinalFromWxid string `json:"final_from_wxid"`
	FinalFromName string `json:"final_from_name"`
	TimeStamp string `json:"timestamp"`
	SendOutScene string `json:"send_out_scene"`
	RobotWxid string `json:"robot_wxid"`
	Event string `json:"event"`
}
/*
"from_wxid": "wxid_dyj8lg3du5lj22",
    "content": "1",
    "to_wxid": "23114933559@chatroom",
    "to_name": "测试开发",
    "msg": "1",
*/

func NewRecipeHandler(c *gin.Context) {
	var reqBody ReqBody
	if err := c.ShouldBindJSON(&reqBody); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"error": err.Error()})
		return
	}
	if strings.Contains(reqBody.Msg, "测试") {
		data := make(map[string]string)
		data["robot_wxid"] = "wxid_dyj8lg3du5lj22"
		data["to_wxid"] = "23114933559@chatroom"
		data["msg"] = "hello I'm Go"
		kam_op.SendText(data)
	}
	c.JSON(http.StatusOK, reqBody)
}
/*
// Recipes API
//
// This is a sample recipes API. You can find out more about
the API at https://github.com/PacktPublishing/Building-
Distributed-Applications-in-Gin.
//
// Schemes: http
// Host: localhost:8080
// BasePath: /
// Version: 1.0.0
// Contact: Mohamed Labouardy
// <mohamed@labouardy.com> https://labouardy.com
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
// swagger:meta
*/
func main() {
	router := gin.Default()
	router.POST("/api/robot/notice", NewRecipeHandler)
	_ = router.Run(":80")
}
